package cn.shanke.torrentmanagerserver.btclient.model;

import lombok.Data;
import nl.stil4m.transmission.api.domain.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class TmTorrentInfo {
    private String id;
    private Long activityDate;
    private Long addedDate;
    private Long bandwidthPriority;
    private String comment;
    private Long corruptEver;
    private String creator;
    private Long dateAdded;
    private Long dateCreated;
    private Long desiredAvailable;
    private Long doneDate;
    private String downloadDir;
    private Long downloadedEver;
    private Long downloadLimit;
    private Boolean downloadLimited;
    private Long error;
    private String errorString;
    private Long eta;
    private Long etaIdle;
    private List<File> files;
    private List<FileStat> fileStats;
    private String hashString;
    private Long haveUnchecked;
    private Long haveValid;
    private Boolean honorsSessionLimits;
    private Boolean isFinished;
    private Boolean isPrivate;
    private Boolean isStalled;
    private Long leftUntilDone;
    private String magnetLink;
    private Long manualAnnounceTime;
    private Long maxConnectedPeers;
    private Double metadataPercentComplete;
    private String name;
    private Long peerLimit;
    private List<Peer> peers;
    private Long peersConnected;
    private Object peersFrom;
    private Long peersGettingFromUs;
    private Long peersSendingToUs;
    private Double percentDone;
    private String pieces;
    private Long pieceCount;
    private Long pieceSize;
    private List<Integer> priorities;
    private Long queuePosition;
    private Long rateDownload;
    private Long rateUpload;
    private Double recheckProgress;
    private Long secondsDownloading;
    private Long secondsSeeding;
    private Long seedIdleLimit;
    private Long seedIdleMode;
    private Double seedRatioLimit;
    private Long seedRatioMode;
    private Long sizeWhenDone;
    private Long startDate;
    private Long status;
    private List<Tracker> trackers;
    private List<TrackerStat> trackerStats;
    private Long totalSize;
    private String torrentFile;
    private Long uploadedEver;
    private Long uploadLimit;
    private Boolean uploadLimited;
    private Double uploadRatio;
    private List wanted;
    private List webseeds;
    private Long webseedsSendingToUs;

    public static TmTorrentInfo wrapTransmission(TorrentInfo info) {
        TmTorrentInfo tti = null;
        if (info != null) {
            tti = new TmTorrentInfo();
            tti.id = info.getId() + "";
            tti.name = info.getName();
            tti.downloadDir = info.getDownloadDir();
            tti.hashString = info.getHashString();
            tti.totalSize = info.getTotalSize();
            tti.status = info.getStatus();
            tti.addedDate = info.getAddedDate();
            tti.trackers = info.getTrackers();
            tti.isPrivate = info.getPrivate();
            tti.magnetLink = info.getMagnetLink();
            // more than simple
            tti.trackerStats = info.getTrackerStats();
            tti.hashString = info.getHashString();
            tti.files = info.getFiles();
            tti.rateDownload = info.getRateDownload();
            tti.rateUpload = info.getRateUpload();
            tti.downloadedEver = info.getDownloadedEver(); // 应该是单次已下载
            tti.leftUntilDone = info.getLeftUntilDone(); // 剩余下载
            tti.comment = info.getComment();
            tti.errorString = info.getErrorString();
        }

        return tti;
    }

    public static List<TmTorrentInfo> wrapTransmission(List<TorrentInfo> infos) {
        if (infos == null || infos.isEmpty()) {
            return new ArrayList<>();
        }
        return infos.stream().map(info->wrapTransmission(info)).collect(Collectors.toList());
    }
}
